package com.abc.data.scope;

import com.abc.data.scope.dao.CompanyMapper;
import com.abc.data.scope.model.Company;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;


public class HelloMybatis {

    @Test
    public void testList() throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        try (SqlSession session = sqlSessionFactory.openSession()) {
            CompanyMapper mapper = session.getMapper(CompanyMapper.class);
            List<Company> companies = mapper.selectCompanies();
            for (Company c : companies) {
                System.out.println("company: " + c.getName());
            }
        }
    }

}
